<template>
	<view class="information-change">
		<view class="content-view">
			<view class="content-item" v-if="hidden">
				<view class="content-item-left ml35">审核状态</view>
				<view class="content-item-right" @click="showPicker(columns1,1)">
					<view v-if="form.adviceState==0" class="fs32 cg">同意</view>
					<view v-if="form.adviceState==1" class="fs32 cred">退回</view>
					<u-icon name="arrow-right" color="#333333" size="16" style="margin-left: 10rpx;"></u-icon>
				</view>
			</view>

			<view class="content-item disabled" v-if="hidden">
				<view class="content-item-left ml35">审核人签字</view>
				<view class="content-item-right">
					<u--input border="none" v-model="form.name2" disabled disabledColor="#EFF2F2 ">
					</u--input>
				</view>
			</view>

			<view class="content-item disabled" v-if="hidden">
				<view class="content-item-left"><span class="required">*</span>审核人签字日期</view>
				<view class="content-item-right">
					<u--input border="none" v-model="form.auditTime" disabled disabledColor="#EFF2F2 ">
					</u--input>
				</view>
			</view>

			<view class="content-item" v-if="form.adviceState==0 && form.evaGrade == '02' && (form.currentState2 == 'ds_ldhd' || form.currentState2 == 'sheng_ldhd')">
				<view class="content-item-left"><span class="required">*</span>发送人</view>
				<view class="content-item-right" @click="showOptionCard">
					<u--input border="none" v-model="form.toPerson" disabled disabledColor="#ffffff">
					</u--input>
					<u-icon name="arrow-right" color="#333333" size="16" style="margin-left: 10rpx;"></u-icon>
				</view>
			</view>
			<view class="content-item" v-if="form.adviceState==1" @click="showPicker(columns2,2)">
				<view class="content-item-left"><span class="required">*</span>退回环节</view>
				<view class="content-item-right">
					<u--input border="none" v-model="form.name6" disabled disabledColor="#ffffff">
					</u--input>
					<u-icon name="arrow-right" color="#333333" size="16" style="margin-left: 10rpx;"></u-icon>
				</view>
			</view>
			<view class="content-item">
				<view class="content-item-left"><span class="required">*</span>审核意见</view>
				<view class="content-item-right">
					<u--input border="none" v-model="form.auditInfo"
						placeholderStyle="color:#B5B5B5;text-align:right">
					</u--input>
				</view>
			</view>
		</view>
		<view class="btn-view">
			<view class="btn but1" @click="quit">取消</view>
			<view class="btn but2" @click="submit">确定</view>
		</view>
		<view>
			<u-picker :show="show" @cancel="show=false" @confirm="confirm" :columns="columns" keyName="label">
			</u-picker>
		</view>
		<optionCard :show="showfsr" @showPopup="showfsr=false" @listItem="listItemfs" :event="true"
			:roleCode="roleCode" :selfFlag="selfFlag">
		</optionCard>
	</view>
</template>

<script>
	import optionCard from './components/option-card.vue'
	const d = new Date()
	const year = d.getFullYear()
	let month = d.getMonth() + 1
	month = month < 10 ? `0${month}` : month
	let date = d.getDate()
	date = date < 10 ? `0${date}` : date
	export default {
		components:{
			optionCard,
		},
		data() {
			return {
				selfFlag:'',
				roleCode:'',
				showfsr:false,
				show: false,
				columns: [
					[]
				],
				columns1: [
					[{
						label: '同意',
						// 其他属性值
						id: 0
						// ...
					}, {
						label: '退回',
						id: 1
					}]
				],
				columns2: [
					[]
				],
				hidden:true,
				flag: 0,
				form: {
					currentState2:'',//当前详细流程
					evaGrade:'',//评估等级
					troubleId: '', //隐患id,
					adviceState: '', //审核状态key
					name2: '',//审核人签字
					auditTime: '',//签字时间
					toPerson: '',//回显发送人
					processId:'',//退回环节value
					name6: '',//退回环节text
					auditInfo: '',
					toPersonId:'',
				},
				pickerIndex:0,
				// show:false,
				//默认时间
				// defaultDateMultiple: [`${year}-${month}-${date}`],
			}
		},
		onLoad(e) {
			if (e.flag) {
				this.form.adviceState = e.flag
			}
			if(e.hidden){
				this.hidden = false
			}
			if (e.item) {
				let item = JSON.parse(e.item)
				console.log('item',item)
				let userInfo = uni.getStorageSync('userInfo')
				let date1 = `${year}-${month}-${date}`
				this.form.troubleId = item.troubleId
				this.form.auditTime = date1
				this.form.name2 = userInfo.userName
				this.form.evaGrade = item.evaGrade
				this.form.currentState2 = item.currentState2
				this.form.wsflag = item.wsflag
				this.form.dsflag = item.dsflag
				console.log(this.form)
			}
		},
		mounted() {
			this.link()
		},
		methods: {
			quit(){
				uni.navigateBack({
					delta:1
				})
			},
			//选人回调
			listItemfs(e){
				this.form.toPersonId = e.id 
				this.form.toPerson = e.userName
				this.showfsr=false
			},
			//显示弹框
			async showOptionCard(){
				let params = {
					evaGrade:this.form.evaGrade,
					currentState2:this.form.currentState2,
					wsflag:this.form.wsflag,
					dsflag:this.form.dsflag,
				}
				let {resultValue:res} = await this.request(this.$api.getHiddenDangerUserRoleCode,params,'POST')
				console.log(res)
				this.roleCode = res.roleCode
				this.selfFlag = res.selfFlag
				this.showfsr=true
			},
			//退回环节
			async link() {
				let params = {
					troubleId: this.form.troubleId
				}
				let {resultValue:res} = await this.request(this.$api.queryProcessInfo, params, "POST")
				res.forEach((item)=>{
					this.columns2[0].push({
						label: item.text,
						id: item.value
					})
				})
				console.log(this.columns2)
			},
			showPicker(e,x){
				this.pickerIndex = x
				this.columns = e
				this.show = true
			},
			confirm(e) {
				if(this.pickerIndex==1){
					// console.log(e.value)
					this.form.adviceState = e.value[0].id
				}else{
					this.form.name6 = e.value[0].label
					this.form.processId = e.value[0].id
				}
				this.show = false
			},
			async submit() {
				if(this.form.adviceState == 0){
					console.log(this.form.adviceState,this.form.evaGrade,this.form.currentState2)
					if(this.form.adviceState==0 && this.form.evaGrade == '02' && (this.form.currentState2 == 'ds_ldhd' || this.form.currentState2 == 'sheng_ldhd')){
						if(this.form.toPersonId==''){
							uni.showToast({
								icon:'none',
								title:'发送人不能为空'
							})
							return
						}
					}
					let res = await this.request(this.$api.auditHiddenInfo,this.form,"POST")
					console.log(res)
					uni.showToast({
						icon:'success',
						title:'审核成功'
					})
					setTimeout((item)=>{
						uni.navigateBack({
							delta:2
						})
					},1000)
				}else{
					let res = await this.request(this.$api.rollback,this.form,"POST")
					console.log(res)
					uni.showToast({
						icon:'success',
						title:'退回成功'
					})
					setTimeout((item)=>{
						uni.navigateBack({
							delta:2
						})
					},1000)
				}
			},

		}
	}
</script>

<style scoped>
	.information-change {
		min-height: calc(100vh - 44rpx);
		background: #F1F2F5;
		box-sizing: border-box;
		padding: 20rpx 0;
	}

	.content-view {
		background: white;
	}

	.content-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 28rpx 40rpx;
		padding-left: 20rpx;
		border-bottom: 2rpx solid #F5F5F5;
	}

	.content-item-left {
		font-size: 32rpx;
		color: #333333;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
	}

	.content-item-right {
		width: 50%;
		display: flex;
		justify-content: flex-end;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
	}

	>>>.uni-input-input {
		text-align: right;
		font-size: 32rpx;
		color: #65717D;
	}

	.password-desc {
		font-size: 28rpx;
		color: #999;
		padding: 28rpx 40rpx 0;
	}

	.btn-view {
		display: flex;
		justify-content: space-between;
		padding: 60rpx 40rpx 40rpx 40rpx;
		box-sizing: border-box;
	}


	.btn {
		box-sizing: border-box;
		width: 300rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		text-align: center;
		border-radius: 14rpx;
		box-sizing: border-box;
	}

	.but1 {
		border: 1px solid #3473F9;
		color: #3473F9;
	}

	.but2 {
		background-color: #3473F9;
		color: #FFFFFF;
	}
</style>
